<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('修改商户信息')"/>
    <th:block th:include="include :: bootstrap-fileinput-css"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-shop-edit" th:object="${optShop}">
        <input name="shopId" th:field="*{shopId}" type="hidden">
        <div class="form-group">
            <label class="col-sm-2 control-label"><span
                    style="color: red;">*</span>商户名称：</label>
            <div class="col-sm-4">
                <input name="shopName" class="form-control" type="text"
                       required maxlength="20" th:field="*{shopName}">
            </div>
            <label class="col-sm-2 control-label"><span style="color: red;">*</span>所在省份：</label>
            <div class="col-sm-4">
                <input name="province" class="form-control" type="text" required th:field="*{province}">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label"><span style="color: red;">*</span>所属部门：</label>
            <div class="col-sm-4">
                <div class="input-group">
                    <input name="deptName" readonly="readonly" onclick="selectDeptTree()" th:field="*{deptName}"
                            id="treeName" type="text" placeholder="请选择归属部门" class="form-control">
                    <span class="input-group-addon"><i class="fa fa-search"></i></span>
                </div>
            </div>
            <label class="col-sm-2 control-label"><span
                    style="color: red;">*</span>所在城市：</label>
            <div class="col-sm-4">
                <input name="city" class="form-control" type="text" required th:field="*{city}">
            </div>


        </div>

        <div class="form-group">

            <label class="col-sm-2 control-label">最低消费：</label>
            <div class="col-sm-4">
                <input name="city" class="form-control" type="text" required th:field="*{minTax}">
            </div>

            <label class="col-sm-2 control-label"><span
                    style="color: red;">*</span>商户地址：</label>
            <div class="col-sm-4">
                <input name="address" class="form-control" type="text"
                       required maxlength="30" th:field="*{shopAddress}">
            </div>
        </div>



        <div class="form-group">

            <label class="col-sm-2 control-label">是否测评店：</label>
            <div class="col-sm-4">
                <div class="radio-box"
                     th:each="dict : ${@dict.getType('sys_yes_no')}">
                    <input type="radio" th:id="${'isTests_' + dict.dictCode}"
                           name="isTests" th:value="${dict.dictValue}"
                           required th:field="*{isTests}"> <label
                        th:for="${'isTests_' + dict.dictCode}"
                        th:text="${dict.dictLabel}"></label>
                </div>
            </div>

            <label class="col-sm-2 control-label">是否中心店：</label>
            <div class="col-sm-4">
                <div class="radio-box"
                     th:each="dict : ${@dict.getType('sys_yes_no')}">
                    <input type="radio" th:id="${'isFocus_' + dict.dictCode}"
                           name="isFocus" th:value="${dict.dictValue}"
                           required th:field="*{isFocus}"> <label
                        th:for="${'isFocus_' + dict.dictCode}"
                        th:text="${dict.dictLabel}"></label>
                </div>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-2 control-label">商户图片：</label>
            <div class="col-sm-4">
                <input class="file" type="file" multiple data-min-file-count="1"
                       accept="image/*" data-theme="fas" id="pic_file" name="pic_file">
            </div>
            <label class="col-sm-2 control-label">商户营业执照：</label>
            <div class="col-sm-4">
                <input class="file" type="file" multiple data-min-file-count="1"
                       accept="image/*" data-theme="fas" id="pic_file2" name="pic_file">
                <span class="help-block m-b-none"><i
                        class="fa fa-info-circle"></i> 提示：请上传正确的营业执照，否则将无法通过审核</span>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: bootstrap-fileinput-js"/>
<script th:inline="javascript">

    var prefix = ctx + "operator/shop"
    $("#form-shop-edit").validate({
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/edit", $('#form-shop-edit').serialize());
        }
    }

    /*用户管理-新增-选择部门树*/
    function selectDeptTree() {
        var treeId = $("#treeId").val();
        var deptId = $.common.isEmpty(treeId) ? "100" : $("#treeId").val();
        var url = ctx + "system/dept/selectDeptTree/" + deptId;
        var options = {
            title: '选择部门',
            width: "380",
            url: url,
            callBack: doSubmit
        };
        $.modal.openOptions(options);
    }

    function doSubmit(index, layero) {
        var tree = layero.find("iframe")[0].contentWindow.$._tree;
        if ($.tree.notAllowParents(tree)) {
            var body = layer.getChildFrame('body', index);
            $("#treeId").val(body.find('#treeId').val());
            $("#treeName").val(body.find('#treeName').val());
            layer.close(index);
        }
    }

    function listByProvinceId() {
        var province = $("#province").val();
        if (!province)
            province = '-1';
        var html = '<option value="">请选择所在城市</option>';
        $.ajax({
            url: ctx + "bussiness/cityinfo/listByProvinceId",
            data: {"province": province},
            dataType: "json",
            type: "post",
            success: function (result) {
                $.each(
                    result.data,
                    function (commentIndex, comment) {
                        html += "<option value='" + comment.cityCode + "'>"
                            + comment.cityName
                            + "</option>";
                    });
                $("#city").html(html);
            }, error: function () {
                $.modal.alertError("服务器发生错误，请稍后重试！");
            }
        })
    }

    var shopImg ='<img src="' + [[${optShop.shopImg}]]+ '" alt="商户图片" ' +
        'class="file-preview-image" style="width:auto;height:auto;max-width:100%;max-height:100%;">';
    $("#pic_file").fileinput({
        initialPreview: [ shopImg ]
    });

    var shlicenseImg ='<img src="' + [[${optShop.shlicense}]]+ '" alt="营业执照" ' +
        'class="file-preview-image" style="width:auto;height:auto;max-width:100%;max-height:100%;">';
    $("#pic_file2").fileinput({
        initialPreview: [ shlicenseImg ]
    });

</script>
</body>
</html>
